﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Collections.Specialized;
using System.Web.Mvc;
using System.Collections;

namespace System.Collections.Specialized
{
    public static class NameValueCollectionHelper
    {
        /// <summary>
        /// Adds to FormCollection.Get, for getting same Key name, when using an expresion.
        /// EX: @Html.HiddenFor(model => model.Id)
        ///     FormCollection.Get(model => model.Id)
        ///     The above would return the value for hidden form data.
        /// </summary>
        /// <typeparam name="T">The type of the members of values.</typeparam>
        /// <param name="NameColObj">The collection</param>
        /// <param name="expression">Expression to lookup</param>
        /// <returns>value of the expression data.</returns>
        public static string Get<T>(this NameValueCollection NameColObj, Expression<Func<T, object>> expression)
        {
            if (NameColObj.isNull()) return String.Empty;
            return NameColObj.Get(ExpressionHelper.GetExpressionText(expression));
        }
    }
}
